package Offer.offer;

/**
 * 替换空格
 * @author leiwenkang
 * @date 2020/4/6
 */
public class Test04替换空格 {
    public static void main(String[] args) {
        System.out.println(replaceBlank("we are happy"));
    }

    public static String replaceBlank(String str) {
        if (str == null || str.length() == 0) {
            return str;
        }
        char[] ch = str.toCharArray();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < ch.length; i++) {
            if (ch[i] != ' ') {
                sb.append(ch[i]);
            } else {
                sb.append("20%");
            }
        }
        return sb.toString();
    }
}
